#ifndef CHESSTIMER_H
#define CHESSTIMER_H

#include "time.h"

#ifdef WIN32//option: change to getSystemTime for possibly more accuracy, at the expense of possibly more costly time testing
#define MYTIME clock_t
#define MYGETTIME clock
#define MYSECONDS(A) (((double)(A)) / CLOCKS_PER_SEC)
#else
#include "sys/time.h"
#define MYTIME double
#define MYGETTIME linux_time
#define MYSECONDS(A) (A)
inline double linux_time()
{
	static timeval temp;//static to prevent stack reallocation every call
	gettimeofday(&temp, NULL);
	return temp.tv_sec + (double)temp.tv_usec / 1000000.0;//microseconds...seriously...
};
#endif

class ChessTimer
{
	double myduration, elapsed;
	MYTIME mystart, myend;//end is a member variable so it doesn't get allocated on the stack when stop() is called
	bool running;
public:
	ChessTimer();
	void setTime(double duration);//works while running, but sets duration since start, not since current time
	void start();
	void stop();
	double timeLeft();
	double timeElapsed();
	bool isRunning();//i don't know why someone would need this, but here it is
};
#endif
